{% extends '../layout.html.twig' %}

{% block title %}Orders | Crypto Bot{% endblock %}

{% block content %}
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>Orders</h1>
                </div>
            </div>
        </div>
    </section>

    <div class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-3">

                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">
                                <i class="fas fa-text-width"></i>
                                Pairs
                            </h3>

                            <small class="float-sm-right"><input class="filter-pairs" type="text" placeholder="Filter"></small>
                        </div>
                        <div class="card-body">
                            <ul class="list-unstyled">
                                {% for pair in pairs %}
                                    <li class="pair-item"><a href="/orders/{{ pair|url_encode }}">{{ pair }}</a></li>
                                {% endfor %}
                            </ul>
                        </div>
                    </div>
                </div>

                {% block page_content %}{% endblock %}
            </div>
        </div>
    </div>
{% endblock %}


{% block javascript %}
    <script>
        // filter pairs
        $(function() {
          var filterTimeout = null;
          $( ".filter-pairs" ).keyup(function() {
            var me = $(this);

            if (filterTimeout != null) {
              clearTimeout(filterTimeout);
            }
            filterTimeout = setTimeout(function() {
              var filter = me.val();

              var card = me.closest('.card');
              if (filter.length === 0) {
                card.find('li.pair-item').show()
                return;
              }

              card.find('li.pair-item').each(function() {
                if ($(this).text().toLowerCase().includes(filter.toLowerCase())) {
                  $(this).show()
                } else {
                  $(this).hide()
                }
              });
            }, 250);
          });
        });
    </script>
{% endblock javascript %}